package com.example.springcloudeurekaserverproducer.controller;

import com.alibaba.fastjson.JSON;

import java.io.Serializable;
import java.util.Objects;

public class BaseBean<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final int NO_LOGIN = -1;

	public static final int SUCCESS = 0;

	public static final int FAIL = 1;

	public static final int NO_PERMISSION = 2;

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		BaseBean<?> baseBean = (BaseBean<?>) o;
		return code == baseBean.code &&
				Objects.equals(msg, baseBean.msg) &&
				Objects.equals(data, baseBean.data);
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}

	@Override
	public int hashCode() {

		return Objects.hash(code, msg, data);
	}

	private int code = SUCCESS;
	private String msg = "success";

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}


	private T data;

	public BaseBean() {
		super();
	}

	public BaseBean(T data) {
		super();
		this.data = data;
	}

	public BaseBean(Throwable e) {
		super();
		this.msg = e.toString();
		this.code = FAIL;
	}
}

